#include <iostream>
#include <pthread.h>
#include <vector>
#include <unistd.h>

class thread_data
{
public:
    pthread_t id;
    char thread_name[100];
};

void* thread_routine(void* arg)
{
    thread_data* data = static_cast<thread_data*>(arg);
    std::cout << data->thread_name <<std::endl;
    return nullptr;
}

int main()
{
    std::vector<thread_data> thread(10);
    for (int i = 0; i < 10; i++)
    {
        sprintf(thread[i].thread_name, "我是线程%d     ", i + 1);
        pthread_create(&(thread[i].id), nullptr, thread_routine, &thread[i]);
        //sleep(1);
    }
    //等待线程结束
    for(int i = 0; i < 10; i++)
    {
        pthread_join(thread[i].id, nullptr);
    }

    return 0;
}